/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ipti.br.tag.util;

import org.ipti.br.tag.entity.Hb;
import org.ipti.br.tag.entity.Human;
import org.ipti.br.tag.entity.enums.Sex;
import java.util.Calendar;

/**
 *
 * @author FelipeMSX
 */
public class HbUtil {
    
    public static int monthsBetweenDates(Calendar initialDt , Calendar finalDt) {
        return (finalDt.get(Calendar.YEAR)*12+finalDt.get(Calendar.MONTH)) -
                (initialDt.get(Calendar.YEAR)*12+initialDt.get(Calendar.MONTH));
    }
    
    public static boolean avaliate(Hb hb) {
        return avaliate(monthsBetweenDates(hb.getHuman().getBirthday(), hb.getLastModified()),
                hb.getHemoglobineTax(), hb.getHuman());
    }
    
    public static boolean avaliate(int months, float hemoglobineTax, Human human) {
       if ( (months > 24) && (months < 60) ) {
           if (hemoglobineTax >= 11.0) {
               return false;
           } else {
               return true;
           }
       } else if (  (months >= 60) && (months < 144)) {
           if (hemoglobineTax >= 11.5) {
               return false;
           } else {
               return true;
           }
       } else if (  (months >= 144) && (months < 180)) {
            if (hemoglobineTax >= 12) {
               return false;
           } else {
               return true;
           }
       } else if (  (months >= 180) && (human.getSex() == Sex.MALE)  ) {
            if (hemoglobineTax >= 13) {
               return false;
           } else {
               return true;
           }
       } else if (  (months >=180) && (human.getSex() == Sex.FEMALE)  ) {
            if (hemoglobineTax >= 12) {
               return false;
           } else {
               return true;
           }
       }
       return false;
   }
}
